import { notFound, redirect } from "next/navigation";

import { ProjectDetailView } from "@/components/projects/project-detail-view";
import { getAuthenticatedUser, getProjectDetail } from "@/lib/server-data";

interface ProjectDetailPageProps {
  params: {
    id: string;
  };
}

export default async function ProjectDetailPage({ params }: ProjectDetailPageProps) {
  const user = await getAuthenticatedUser();

  if (!user) {
    redirect("/auth/login");
  }

  const project = await getProjectDetail(params.id);

  if (!project) {
    notFound();
  }

  return (
    <section className="mx-auto flex w-full max-w-5xl flex-col gap-6 px-6 py-12">
      <ProjectDetailView initialProject={project} />
    </section>
  );
}
